package org.hcf.utils.exceltemp;

import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.hcf.utils.entity.Emp;
import org.hcf.utils.excel.poi.base.exp.SimpleExcelHelper;
import org.hcf.utils.excel.poi.base.exp.ValidationDataHandler;
import org.hcf.utils.excel.poi.base.exp.header.StringTableHeader;
import org.hcf.utils.excel.poi.base.exp.header.TableHeader;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author hecf
 * @date 2021/9/5
 */
@Data
public class EmpElsxHandler2 extends SimpleExcelHelper<Emp> {
    @Override
    protected List<TableHeader<Emp>> initHeaders() {
        headers = new ArrayList<>();

        headers.add(new StringTableHeader<>("姓名", 4000, Emp::getName));
        headers.add(new StringTableHeader<>("部门", 4000, Emp::getDep));
        headers.add(new StringTableHeader<>("角色", 4000, Emp::getRole));
        headers.add(new StringTableHeader<>("手机号码", 4000, Emp::getPhone));
        headers.add(new StringTableHeader<>("密码", 4000, Emp::getPwd));
        headers.add(new StringTableHeader<>("身份证号", 4000, Emp::getIdentityNo));

        return headers;
    }


    protected Collection<String> depValidationDatas;
    protected Collection<String> roleValidationDatas;

    /** 请先初始化 validationDatas再 调用 initValidationDataHandlers*/
    @Override
    public List<ValidationDataHandler> initValidationDataHandlers() {
        validationDataHandlers = new ArrayList<>();
        if(CollectionUtils.isNotEmpty(this.depValidationDatas)) {
            validationDataHandlers.add(new ValidationDataHandler(this, "depNameList", true, this.depValidationDatas,1));
        }
        if(CollectionUtils.isNotEmpty(this.roleValidationDatas)) {
            validationDataHandlers.add(new ValidationDataHandler(this, "roleNameList", true, this.roleValidationDatas, 2));
        }
        return validationDataHandlers;
    }
}
